home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / bipl.zip / PROGS.ZIP / LABELS.ICN < prev    next >
Text File  |  1992-09-28  |  5KB  |  155 lines

  1. ############################################################################
  2. #
  3. #    File:     labels.icn
  4. #
  5. #    Subject:  Program to format mailing labels
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     December 30, 1991
  10. #
  11. ###########################################################################
  12. #  
  13. #     This program produces labels using coded information taken
  14. #  from the input file.  In the input file, a line beginning with #
  15. #  is a label header.  Subsequent lines up to the next header or
  16. #  end-of-file are accumulated and output so as to be centered hor-
  17. #  izontally and vertically on label forms.  Lines beginning with *
  18. #  are treated as comments and are ignored.
  19. #  
  20. #  Options: The following options are available:
  21. #  
  22. #       -c n Print n copies of each label.
  23. #  
  24. #       -s s Select only those labels whose headers contain a char-
  25. #            acter in s.
  26. #  
  27. #       -t   Format for curved tape labels (the default is to format
  28. #            for rectangular mailing labels).
  29. #  
  30. #       -w n Limit line width to n characters. The default width is
  31. #            40.
  32. #  
  33. #       -l n Limit the number of printed lines per label to n. The
  34. #            default is 8.
  35. #  
  36. #       -d n Limit the depth of the label to n. The default is 9 for
  37. #            rectangular labels and 12 for tape labels (-t).
  38. #  
  39. #     Options are processed from left to right.  If the number of
  40. #  printed lines is set to a value that exceeds the depth of the
  41. #  label, the depth is set to the number of lines.  If the depth is
  42. #  set to a value that is less than the number of printed lines, the
  43. #  number of printed lines is set to the depth. Note that the order
  44. #  in which these options are specified may affect the results.
  45. #  
  46. #  Printing Labels: Label forms should be used with a pin-feed pla-
  47. #  ten.  For mailing labels, the carriage should be adjusted so that
  48. #  the first character is printed at the leftmost position on the
  49. #  label and so that the first line of the output is printed on the
  50. #  topmost line of the label.  For curved tape labels, some experi-
  51. #  mentation may be required to get the text positioned properly.
  52. #  
  53. #  Diagnostics: If the limits on line width or the number of lines
  54. #  per label are exceeded, a label with an error message is written
  55. #  to standard error output.
  56. #  
  57. ############################################################################
  58. #
  59. #  Links: options, buffer
  60. #
  61. #  See also:  address.doc, adllist.icn, adlfiltr.icn, adlcount.icn,
  62. #          adlcheck.icn, zipsort.icn
  63. #
  64. ############################################################################
  65.  
  66. link options, buffer
  67.  
  68. global lsize, repet, llength, ldepth, opts, selectors
  69.  
  70. procedure main(args)
  71.    local y, i, line
  72.  
  73.    selectors := '#'
  74.    lsize := 9
  75.    ldepth := 8
  76.    llength := 40
  77.    repet := 1
  78.    i := 0
  79.    opts := options(args,"c+d+l+s:tw+")
  80.    selectors := cset(\opts["s"])
  81.    if \opts["t"] then {
  82.       lsize := 12
  83.       if ldepth > lsize then ldepth := lsize
  84.       }
  85.    llength := nonneg("w")
  86.    if ldepth := nonneg("l") then {
  87.       if lsize < ldepth then lsize := ldepth
  88.       }
  89.    if lsize := nonneg("d") then {
  90.       if ldepth > lsize then ldepth := lsize
  91.       }
  92.    repet := nonneg("c")
  93.  
  94.    while line := Read() do
  95.       line ? {
  96.          if any('#') & upto(selectors) then nextlbl()
  97.          }
  98.  
  99. end
  100.  
  101. #  Obtain next label
  102. #
  103. procedure nextlbl()
  104.    local label, max, line
  105.    label := [Read()]
  106.    max := 0
  107.    while line := Read() do {
  108.       if line[1] == "*" then next
  109.       if line[1] == "#" then {
  110.          PutBack(line)
  111.          break
  112.          }
  113.       put(label,line)
  114.       max <:= *line
  115.       if *label > ldepth then {
  116.          error(label[1],1)
  117.          return
  118.          }
  119.       if max > llength then {
  120.          error(label[1],2)
  121.          return
  122.          }
  123.       }
  124.    every 1 to repet do format(label,max)
  125. end
  126.  
  127. #  Format a label
  128. #
  129. procedure format(label,width)
  130.    local j, indent
  131.    indent := repl(" ",(llength - width) / 2)
  132.    j := lsize - *label
  133.    every 1 to j / 2 do write()
  134.    every write(indent,!label)
  135.    every 1 to (j + 1) / 2 do write()
  136. end
  137.  
  138. #  Issue label for an error
  139. #
  140. procedure error(name,type)
  141.    static badform
  142.    initial badform := list(lsize)
  143.    case type of {
  144.       1:  badform[3] := "     **** too many lines"
  145.       2:  badform[3] := "     **** line too long"
  146.       }
  147.    badform[1] := name
  148.    every write(&errout,!badform)
  149. end
  150.  
  151. procedure nonneg(s)
  152.    s := \opts[s] | fail
  153.    return 0 < integer(s) | stop("-",s," needs postive numeric parameter")
  154. end
  155.